#include "testsignalhp.h"
#include <QtWidgets>

testsignalhp::testsignalhp(QObject *parent)
    :QObject{parent}
{

}

testsignalhp::~testsignalhp()
{

}

EnHandleResult testsignalhp::OnPrepareConnect(ITcpClient *pSender, CONNID dwConnID, SOCKET socket)
{
    Q_UNUSED(pSender);
    Q_UNUSED(dwConnID);
    Q_UNUSED(socket);
    return HR_OK;
}

EnHandleResult testsignalhp::OnConnect(ITcpClient *pSender, CONNID dwConnID)
{
    char buf[40]{};
    int len{40};
    uint16_t port{};
    pSender->GetRemoteHost(buf,len,port);
    emit signal_connect_notify(dwConnID,QString("IP:%1,port:%2")
                               .arg(buf).arg(port),true);
    return HR_OK;
}

EnHandleResult testsignalhp::OnHandShake(ITcpClient *pSender, CONNID dwConnID)
{
    Q_UNUSED(pSender);
    Q_UNUSED(dwConnID);
    return HR_OK;
}

EnHandleResult testsignalhp::OnReceive(ITcpClient *pSender, CONNID dwConnID, const BYTE *pData, int iLength)
{
    Q_UNUSED(pSender);
    emit signal_msg_notify(dwConnID,pData,iLength);
    return HR_OK;
}

EnHandleResult testsignalhp::OnSend(ITcpClient *pSender, CONNID dwConnID, const BYTE *pData, int iLength)
{
    Q_UNUSED(pSender);
    Q_UNUSED(dwConnID);
    Q_UNUSED(pData);
    Q_UNUSED(iLength);
    return HR_OK;
}

EnHandleResult testsignalhp::OnClose(ITcpClient *pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
{
    Q_UNUSED(enOperation);
    Q_UNUSED(iErrorCode);
    char buf[40]{};
    int len{40};
    uint16_t port{};
    pSender->GetRemoteHost(buf,len,port);
    emit signal_connect_notify(dwConnID,QString("IP:%1,Port:%2").arg(buf).arg(port),false);
    return HR_OK;
}
